<!--用户管理-->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="superTablePage">
    </ex_super_table_page>

    <el-dialog :title="$tt('label_fms_account_log_credit_apply')" :visible.sync="dialogFormVisible" width="580px" height="200px"
      :close-on-click-modal="false">
      <el-form ref="formEl" :model="formValue" :rules="rules" label-width="120px" class="common-form-panel-div"
        style="padding: 0px 10px;">
        <ex_header_spiler :title="$tt('label_fms_account_log_apply_info')"></ex_header_spiler>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_cmp_as_customer')" prop="customerId">
              {{ '[' + formValue.customerCode + '] ' + formValue.customerName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_apply_account_category')">
              {{ $tt('PmsProductTypeEnum__' + formValue.productType) }} - {{ $tt('CurrencyTypeEnum__' +
                formValue.currencyType) }} - {{ $tt('CustomerAccountTypeEnum__' + formValue.accountType) }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_cmp_current_credit')">
              {{ formValue.oldCreditAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_cmp_adjust_as')">
              {{ formValue.newCreditAmount }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_cmp_adjust_reason')">
              {{ formValue.applyReason }}
            </el-form-item>
          </el-col>
        </el-row>

        <ex_header_spiler :title="$tt('label_fms_account_log_examine_result')"></ex_header_spiler>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_fms_account_log_examine_result')">
              <el-radio-group v-model="formValue.type">
                <el-radio label="DONE">{{ $tt('label_fms_account_log_examine_success') }}</el-radio>
                <el-radio label="FAIL">{{ $tt('label_fms_account_log_examine_fail') }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="formValue.type == 'FAIL'">
          <el-col>
            <el-form-item :label="$tt('label_fms_account_log_examine_fail_reason')">
              <el-input v-model="formValue.refuseReason" style="width: 100%;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $tt('label_fms_account_config_cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $tt('label_fms_account_config_confirm') }}</el-button>
      </div>
    </el-dialog>


  </div>
</template>
<script>

let moduleName = "label_fms_account_apply_credit_apply_manage"
import superTablePageFunction from '@/mixin/super-table-page-function';
export default {

  title: moduleName,
  components: {},

  mixins: [superTablePageFunction],
  data() {

    let _this = this

    return {

      dialogFormVisible: false,
      dialogTitle: '',
      formValue: {
        'type': 'DONE'
      },
      rules: {
        companyName: [
          { required: true, message: '请输入企业名称', trigger: 'blur' },
          { min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur' }
        ],
        companyShortCode: [
          { required: true, message: '请输入企业编码', trigger: 'blur' },
          { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
        ]
      }



    };
  },


  watch: {
    'formValue.companyId'(val, old) {

    }
  },

  created() {

    let _this = this

    _this.option = {
      search: {
        model: [
          {
            label: "label_fms_account_cmp_customer",
            key: "customerIds",
            type: 'common_customer_choose',
            attrs: { multiple: true, },
            inputStyle: { 'width': '300px' },
          },
          {
            label: "label_status", key: "status", type: 'select', enum: 'FmsCreditApplyStatus', attrs: { clearable: true },
          },
          {
            label: "label_fms_account_apply_apply_date",
            key: "applyTimeStart",
            type: 'date-picker',
            attrs: { type: "datetime" },
          },
          {
            label: "-",
            key: "applyTimeEnd",
            type: 'date-picker',
            attrs: { type: "datetime" },
          },
          {
            label: "label_fms_account_apply_audit_date",
            key: "auditTimeStart",
            type: 'date-picker',
            attrs: { type: "datetime" },
          },
          {
            label: "-",
            key: "auditTimeEnd",
            type: 'date-picker',
            attrs: { type: "datetime" },
          },
        ],
      },
      action: [
      ],

      table: {
        url: "/fms-api/customer/CustomerCreditApplyRpc/query.json",
        attrs: {
          'cell-style': ({ row, column, rowIndex, columnIndex }) => {
            if (column.property == 'status') {
              return { color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor }
            }
          }
        },
        model: [
          {
            key: 'companyName', label: 'label_fms_account_config_customer_name', align: 'left', attrs: {
              formatter: (r, c, v, i) => {
                return '[' + r.customerCode + '] ' + r.customerName
              }
            }
          },
          {
            key: 'accountType', label: 'label_fms_account_cmp_account_type', width: 120,
            attrs: {
              formatter: (r, c, v, i) => {
                return this.$enumShow(v, 'CustomerAccountTypeEnum')
              }
            }
          },
          {
            key: 'productType', label: 'label_fms_account_cmp_is_product', width: 120,
            attrs: {
              formatter: (r, c, v, i) => {
                return this.$enumShow(v, 'PmsProductTypeEnum')
              }
            }
          },
          {
            key: 'currencyType', label: 'label_fms_account_cmp_account_currency', width: 120,
            attrs: {
              formatter: (r, c, v, i) => {
                return this.$enumShow(v, 'CurrencyTypeEnum')
              }
            }
          },

          { key: 'oldCreditAmount', label: 'label_fms_account_apply_old_quota', align: 'left' },
          { key: 'newCreditAmount', label: 'label_fms_account_apply_adjust_quota', align: 'left' },
          // { key: 'modifyAmount', label: '变更金额', align: 'left' },
          { key: 'submitUserName', label: 'label_fms_account_apply_apply_user', align: 'left', width: 120 },
          { key: 'submitTime', label: 'label_fms_account_apply_apply_date', attrs: { formatter: (r, c, v, i) => { return this.$dateFormat(v) } } },


          {
            key: 'status', label: 'label_fms_account_apply_status',
            width: 120,
            attrs: {
              formatter: (r, c, v, i) => { return this.$enumShow(v, 'FmsCreditApplyStatus') }
            }
          },

          { key: 'auditUserName', label: 'label_fms_account_apply_audit_user', align: 'left', width: 120 },
          { key: 'auditTime', label: 'label_fms_account_apply_audit_date', attrs: { formatter: (r, c, v, i) => { return this.$dateFormat(v) } } },
          { key: 'applyReason', label: 'label_fms_account_apply_apply_reason', align: 'left', width: 120 },

          { key: 'refuseReason', label: 'label_fms_account_apply_refuse_reason', align: 'left', width: 120 },

          {
            type: 'operate', width: 120,
            operate: [
              {
                if: (row) => {
                  return row.status == 'INIT'
                },
                auth:'fms_credit_apply_audit',
                label: 'label_fms_account_apply_audit', click: (row) => {
                  let _this = this
                  let tmpForm = JSON.parse(JSON.stringify(row))
                  tmpForm['type'] = 'DONE'
                  this.formValue = tmpForm
                  this.dialogFormVisible = true
                }
              }
            ],
          }
        ]
      }
    }

  },

  props: {

  },

  destroyed() {

  },

  methods: {

    submitForm() {

      let _this = this

      _this.$refs['formEl'].validate((valid) => {
        if (valid) {

          _this.$ajax({
            url: '/fms-api/customer/CustomerCreditApplyRpc/audit.json',
            // type: 'json',
            data: _this.formValue,
            success: (responseData) => {
              this.$message({
                showClose: true,
                message: '提交成功',
                type: 'success'
              })
              _this.$refs['superTablePage'].reload()
              _this.dialogFormVisible = false
            }
          });

        } else {
          return false;
        }

      });

    }


  }
};

</script>
<style>
.small-btn span {
  font-size: 14px;
}

.small-btn .el-button--small span {
  font-size: 14px;
}
</style>
